<%@ page import="com.ld.manageBook.service.BookService" %>
<%@ page import="com.ld.manageBook.service.impl.BookServiceImpl" %>
<%@ page import="com.ld.manageBook.bean.Books" %>
<%@ page import="java.util.List" %>
<%@ page import="com.ld.manageBook.service.BorrowStatusService" %>
<%@ page import="com.ld.manageBook.service.impl.BorrowStatusImpl" %>
<%@ page import="com.ld.manageBook.bean.User" %>
<%@ page import="com.ld.manageBook.bean.BorrowStatus" %><%--
  Created by IntelliJ IDEA.
  User: 刘邓
  Date: 2023-06-02
  Time: 10:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>查看所有图书</title>
</head>
<body>
<%!
    private BookService bookService = new BookServiceImpl();
	private BorrowStatusService borrowStatusService = new BorrowStatusImpl();
%>
<%
    List<Books> books = bookService.getAllBooks();
    User user = (User)(session.getAttribute("user"));

    BorrowStatus borrowStatus = borrowStatusService.getBorrowStatusByUserName(user.getUsername());
    int borrow_books = 8;
    if(borrowStatus != null){
         borrow_books = 8 - borrowStatus.getBorrow_books();
    }
            out.println("<h1>当前用户可借阅书籍数量: " + borrow_books + "</h1>");
    out.println("<table style='width:60%;height:400px;margin:0 auto; border:1px solid #ccc;cellspacing:0; cellpadding:0'>" +
            "<tr>" +
            "<th>id</th>" +
            "<th>书名</th>" +
            "<th>作者</th>" +
            "<th>价格</th>" +
            "<th>说明</th>" +
            "<th>存量</th>" +
            "<th>总量</th>" +
            "<th>借阅</th>" +
            "</tr>");
    for (Books book : books) {
		Integer id = book.getId();
        String borrowDOM = "<td><a href=" + "'/home/borrowBook.jsp?id=" +id +  "'>" + "借阅" + "</a></td>";
        out.println("<tr>");
        out.println("<td style='text-align:center'>" + book.getId() + "</td>");
        out.println("<td style='text-align:center'>" + book.getName() + "</td>");
        out.println("<td style='text-align:center'>" + book.getAuthor() + "</td>");
        out.println("<td style='text-align:center'>" + book.getPrice() + "</td>");
        out.println("<td style='text-align:center'>" + book.getRemarks() + "</td>");
        out.println("<td style='text-align:center'>" + book.getNumber() + "</td>");
        out.println("<td style='text-align:center'>" + book.getAllnumber() + "</td>");
        out.println(borrowDOM);
        out.println("</tr>");
    }
    out.println("</table>");
%>
</body>
</html>
